<template>
  <!--
      	作者：luoyiming
      	时间：2020-06-01
      	描述：插件中心-分销-分销商用户-编辑
      -->
  <el-dialog title="添加" :visible.sync="dialogVisible" @close="cancelFunc" :close-on-click-modal="false"
             :close-on-press-escape="false" width="60%">
    <el-form :model="formData" ref="formData">
      <el-form-item label="用户编号" :label-width="formLabelWidth" :rules="[{ required: true, message: '请输入用户编号' }]"
                    prop="user_id">
        <el-input type="text" v-model="formData.user_id" autocomplete="off"></el-input>
      </el-form-item>
      <!--      <el-form-item label="微信昵称" :label-width="formLabelWidth">-->
      <!--        <el-input type="text" v-model="formData.nickName" autocomplete="off"></el-input>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="微信头像" :label-width="formLabelWidth">-->
      <!--        <img v-img-url="formData.avatarUrl" width="50" height="50"/>-->
      <!--      </el-form-item>-->
      <el-form-item label="姓名" :label-width="formLabelWidth" :rules="[{ required: true, message: '请输入姓名' }]"
                    prop="real_name">
        <el-input type="text" v-model="formData.real_name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机号" :label-width="formLabelWidth" :rules="[{ required: true, message: '请输入手机号' }]"
                    prop="mobile">
        <el-input type="text" v-model="formData.mobile" autocomplete="off"></el-input>
      </el-form-item>
      <!--      <el-form-item label="等级" :label-width="formLabelWidth">-->
      <!--        <el-select v-model="formData.grade_id" placeholder="-请选择等级-">-->
      <!--          <el-option v-for="(item,index) in gradeList" :key="index" :label="item.name"-->
      <!--                     :value="item.grade_id"></el-option>-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="推荐人ID" :label-width="formLabelWidth">
        <el-input type="text" v-model="formData.referee_id" autocomplete="off"></el-input>
        <div class="tips">如果没有上级则设置为0</div>
      </el-form-item>
      <!--      <el-form-item label="推荐人昵称" :label-width="formLabelWidth">-->
      <!--        <span v-if="formData.referee">{{ formData.referee.nickName }}</span>-->
      <!--      </el-form-item>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelFunc">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import PlusApi from '@/api/plus.js';
import UserApi from '@/api/user.js';

export default {
  data() {
    return {
      /*左边长度*/
      formLabelWidth: '100px',
      /*是否显示*/
      dialogVisible: false,
      /*表单数据模型*/
      formData: {
        user_id: '',
        nickName: '',
        real_name: '',
        mobile: '',
        referee_id: 0
      },
      gradeList: [],
      old_referee_id: 0,
    };
  },
  props: {
    open_add: Boolean,
  },
  watch: {
    open_add: function (n, o) {
      if (n != o) {
        this.dialogVisible = this.open_add;
        if (n) {

        }
      }
    }
  },
  created() {
  },
  methods: {
    addUser() {
      let self = this;
      self.$refs.formData.validate((valid) => {
        if (valid) {
          PlusApi.agentUserAdd(this.formData, true)
            .then(data => {
              self.$message({
                message: '恭喜你，添加成功',
                type: 'success'
              });
              self.cancelFunc(true);
            })
            .catch(error => {
            });
        }
      });
    },
    /*关闭弹窗*/
    cancelFunc(e) {
      let type = 'cancel';
      if (e) {
        type = 'success';
      }
      this.$emit('close', {
        type: type
      });
    }
  }
};
</script>

<style></style>
